#include "interface.hpp"

std::string Interface::errorMessage(ErrorType e)
{
    switch(e) {
        case WRONG_DATE:
            return "The date inserted is invalid";
        default:
            return "Unknow error";
    }
}

std::string Interface::dateToStr(time_duration &pd)
{
    return boost::posix_time::to_simple_string(pd);
}

int Interface::mainLoop()
{
    while(tries > 0) {
        std::string r;

        switch(wd.hours_inserted) {
            case 0:
                r = Interface::getUserInput("Start hour");
                break;
            case 1:
                r = Interface::getUserInput("Interval hour");
                break;
            case 2:
                r = Interface::getUserInput("Back hour");
                break;
            case 3:
                r = Interface::getUserInput("Exit hour");
                tries = 0;
                break;
        }

        if(!wd.getHour(r)) {
            Interface::showMessage(errorMessage(WRONG_DATE));
            tries--;
        }
    }

    processResults();

    return 0;
}

bool Interface::processResults()
{
    time_duration morning = wd.hours[0] + wd.hours[1];
    time_duration evening = wd.hours[2] + wd.hours[3];

    Interface::showMessage("Total: " + dateToStr(day) + "\n");

    return true;
}
